﻿#ifndef BSTRVIEW_INCLUDE
#define BSTRVIEW_INCLUDE

#include <stdlib.h>
#include "bstrlib.h"

#ifdef __cplusplus

namespace Bstrlib
{
	struct CBStringView : public tagbstring
	{
		// Constructors
		CBStringView();
		CBStringView(const char* s);
		CBStringView(int len, const char* s);
		CBStringView(const CBStringView& b);
		CBStringView(const tagbstring& x);
		CBStringView(const void* blk, int len);

		~CBStringView();

		// = operator
		const CBStringView& operator =(const char* s);
		const CBStringView& operator =(const CBStringView& b);
		const CBStringView& operator =(const tagbstring& x);

		// Comparison operators
		bool operator ==(const CBStringView& b) const;
		bool operator ==(const char* s) const;
		bool operator ==(const unsigned char* s) const;
		bool operator !=(const CBStringView& b) const;
		bool operator !=(const char* s) const;
		bool operator !=(const unsigned char* s) const;
		bool operator <(const CBStringView& b) const;
		bool operator <(const char* s) const;
		bool operator <(const unsigned char* s) const;
		bool operator <=(const CBStringView& b) const;
		bool operator <=(const char* s) const;
		bool operator <=(const unsigned char* s) const;
		bool operator >(const CBStringView& b) const;
		bool operator >(const char* s) const;
		bool operator >(const unsigned char* s) const;
		bool operator >=(const CBStringView& b) const;
		bool operator >=(const char* s) const;
		bool operator >=(const unsigned char* s) const;

		// Accessors
		int length() const { return slen; }

		unsigned char character(int i) const
		{
			if (static_cast<unsigned>(i) >= static_cast<unsigned>(slen))
			{
				return '\0';
			}
			return data[i];
		}

		unsigned char operator [](int i) const { return character(i); }

		int caselessEqual(const CBStringView& b) const;
		int caselessCmp(const CBStringView& b) const;
		int boyer_moore_find(const char* b, int pos = 0) const;
		int boyer_moore_caselessfind(const char* b, int pos = 0) const;
		int find(const CBStringView& b, int pos = 0) const;
		int find(const char* b, int pos = 0) const;
		int caselessfind(const CBStringView& b, int pos = 0) const;
		int caselessfind(const char* b, int pos = 0) const;
		int find(char c, int pos = 0) const;
		int reversefind(const CBStringView& b, int pos) const;
		int reversefind(const char* b, int pos) const;
		int caselessreversefind(const CBStringView& b, int pos) const;
		int caselessreversefind(const char* b, int pos) const;
		int reversefind(char c, int pos) const;
		int findchr(const CBStringView& b, int pos = 0) const;
		int findchr(const char* s, int pos = 0) const;
		int reversefindchr(const CBStringView& b, int pos) const;
		int reversefindchr(const char* s, int pos) const;
		int nfindchr(const CBStringView& b, int pos = 0) const;
		int nfindchr(const char* s, int pos = 0) const;
		int nreversefindchr(const CBStringView& b, int pos) const;
		int nreversefindchr(const char* s, int pos) const;

		// Extraction method.
		CBStringView midstr(int left, int len) const;
	};
}

#endif

#endif
